package com.teachoa.bean;

import com.jfinal.plugin.activerecord.Model;
import com.teachoa.util.IDUtil;
import com.teachoa.util.Maps;

@SuppressWarnings("unchecked")
public class TeacherStudent extends Model<TeacherStudent> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2509918064564264958L;
	
	public static final TeacherStudent dao = new TeacherStudent();
	
	public void deleteByStudentIdAndTeacherId(String studentId, String teacherId) {
		TeacherStudent ts = dao.findFirst("select * from teacher_student where student_id = ? and teacher_id = ?"
				, new Object[]{studentId, teacherId});
		ts.delete();
	}
	
	public void createRelation() {
		
		User userDao = User.dao;
		String s1 = userDao.findUserByUserName("学生1").getStr("id");
		String s2 = userDao.findUserByUserName("学生2").getStr("id");
		String s3 = userDao.findUserByUserName("学生3").getStr("id");
		String s4 = userDao.findUserByUserName("学生4").getStr("id");
		
		String t1 = userDao.findUserByUserName("老师1").getStr("id");
		String t2 = userDao.findUserByUserName("老师2").getStr("id");
		String t3 = userDao.findUserByUserName("老师3").getStr("id");
		
		dao.setAttrs(Maps.newHashMap("id", IDUtil.getId(), "teacher_id", t1, "student_id", s1));
		dao.save();
		dao.setAttrs(Maps.newHashMap("id", IDUtil.getId(), "teacher_id", t1, "student_id", s2));
		dao.save();
		dao.setAttrs(Maps.newHashMap("id", IDUtil.getId(), "teacher_id", t2, "student_id", s3));
		dao.save();
		dao.setAttrs(Maps.newHashMap("id", IDUtil.getId(), "teacher_id", t2, "student_id", s4));
		dao.save();
		dao.setAttrs(Maps.newHashMap("id", IDUtil.getId(), "teacher_id", t3, "student_id", s3));
		dao.save();
	}

}
